import json

import requests
from api.baseapi import BaseApi
from api.gettoken.gettoken import GetToken
from url.tag import tagurl
class TagApi(BaseApi):

    def create(self,data=None):
        """
        创建标签
        """

        #请求url
        url = self.getUrl(tagurl.createUrl+"?access_token=%s" % GetToken().getToken())
        self.logs("请求地址",url)

        #请求参数
        parma = {
            "tagname": "ew",
            "tagid": "19"
        }

        if data!=None:
            parma=data

        self.logs("请求参数",json.dumps(parma))

        #获取响应数据
        res = requests.post(url, json=parma)

        #判断接口请求是否成功
        assert res.status_code ==200

        self.logs("获取响应数据", json.dumps(res.json()))

        return res

    def delete(self,tagid):
        """
        删除标签
        :return:
        """

        #请求url
        url = self.getUrl(tagurl.deleteUrl)
        self.logs("请求地址",url)

        #请求参数
        param = {
            "access_token":GetToken().getToken(),
            "tagid":tagid
        }
        self.logs("请求参数",json.dumps(param))


        #获取响应数据
        res = requests.get(url,params=param)
        self.logs("获取响应数据", json.dumps(res.json()))


if __name__ == '__main__':
    TagApi().create()
    # TagApi().delete("19")
